package com.qing.demo.netty.redis;

import cn.hutool.json.JSONUtil;
import com.qing.demo.netty.domain.MsgAgreement;
import com.qing.demo.netty.util.CacheUtil;
import com.qing.demo.netty.util.MsgUtil;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author caozhipeng
 * @date 2025/8/7
 */
@Slf4j
@Service
public class MsgAgreementReceiver extends AbstractReceiver {
    @Override
    public void receiveMessage(Object message) {
        log.info("接收到Push消息：{}",message);
        MsgAgreement msgAgreement= JSONUtil.toBean(message.toString(),MsgAgreement.class);
        String toChannelId=msgAgreement.getToChannelId();
        Channel channel= CacheUtil.cacheChannel.get(toChannelId);
        if(null==channel)return;
        channel.writeAndFlush(MsgUtil.obj2Json(msgAgreement));
    }
}
